package zjh_20230308;

import java.util.Arrays;

public class noReapetArrayList {
    private Object[] obj;
    private int size;

    public noReapetArrayList() {
        obj = new Object[1];
        size = 0;
    }

    public boolean add(Object element) {
        if (size == obj.length) {
            grow();
        }
        if (!contain(element)) {
            obj[size++] = element;
            return true;
        } else {
            return false;
        }

    }

    int indexOfRange(Object o, int start, int end) {
        Object[] es = obj;
        if (o == null) {
            for (int i = start; i < end; i++) {
                if (es[i] == null) {
                    return i;
                }
            }
        } else {
            for (int i = start; i < end; i++) {
                if (o.equals(es[i])) {
                    return i;
                }
            }
        }
        return -1;
    }

    public int indexOf(Object o) {
        return indexOfRange(o, 0, size);
    }

    public boolean contain(Object o) {
        return indexOf(o) >= 0;
    }

    private void grow() {
        Object[] newData = new Object[obj.length + 1];
        System.arraycopy(obj, 0, newData, 0, newData.length - 1);
        obj = newData;
    }
    public int size(){
        return this.size;
    }

}

class Test {
    public static void main(String[] args) {
        noReapetArrayList noReapetArrayList = new noReapetArrayList();
        noReapetArrayList.add("1");
        noReapetArrayList.add("2");
        System.out.println(noReapetArrayList.add("3"));
        System.out.println(noReapetArrayList.add("2"));
        System.out.println(noReapetArrayList.add("4"));
        System.out.println(noReapetArrayList.add("2"));
        System.out.println(noReapetArrayList.add("1"));
        System.out.println(noReapetArrayList.size());
    }
}
